package cn.edu.example.service.impl;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.example.dao.StudentDao;
import cn.edu.example.dao.UserDao;
import cn.edu.example.po.Student;
import cn.edu.example.po.User;
import cn.edu.example.service.UserService;
/**
 * 鐢ㄦ埛Service鎺ュ彛瀹炵幇绫�
 */
@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {
	// 娉ㄥ叆UserDao
	@Autowired
	private UserDao userDao;
	
	@Autowired
	private StudentDao studentDao;
	// 閫氳繃璐﹀彿鍜屽瘑鐮佹煡璇㈢敤鎴�
	@Override
	public User findUser(String usercode, String password) {
		User user = this.userDao.findUser(usercode, password);
		return user;
	}
	@Override
	public Integer createUser(User user) {
		Student student = new Student();
		student.setName(user.getName());
		student.setIDcard(user.getIDcard());
		student.setStatus("未考试");
		student.setTrain_id(""+UUID.randomUUID().toString().replace("-",""));
		int rows = this.studentDao.createStu(student);
		System.out.print(rows);
		if(rows > 0) {
			Integer stu_id  = this.studentDao.getStubyIDcard(user.getIDcard());
			user.setStu_id(stu_id);
		}
		return this.userDao.createUser(user);
	}
	
	
}
